/**
 * Aqui guardamos la certificacion que selecciono dando clic en la celda
 */

appBosch.certification = null;
appBosch.iRow = 1;
var dataSource;
var grid;

$(document).ready(function () {
    /**
     * Tooltip de las categorias, muestra las certificaciones requeridas y el 
     * entrenamiento requerido
     */
    $('div.config-line').kendoTooltip({
        filter: "div.categorization",
        content: kendo.template($('#templateCategories').html())
    });
    /**
     * Al dar clic sobre los iconos de las categorias ocultamos/mostramos las
     * certificaciones de ese nivel.
     */
    $('div.config-line div.categorization').click(function () {
        $(this).toggleClass('disabled');
        var id = $(this).data('id');
        $('div.certification[data-level="' + id + '"]').parents('tr').toggle();
    });


    $('#grid').on('dblclick', 'div.certification.lock', function () {
        alert('Esta certificacion esta bloqueada');
    });

    appBosch.template = kendo.template($('#templateConfigs').html());
    appBosch.templateTraining = kendo.template($('#templateTraining').html());
    appBosch.templateProgress = kendo.template($('#templateProgress').html());
    /// Usuario
    $(document).on('dblclick', 'div.ab-name, div.ab-nomina', function () {

        if (appBosch.jsPermissions.crud.read === false) {
            /**
             * Si no tiene permisos de lectura no les permitimos acceder a los 
             * detalles de la certificación.
             */
            return;
        }
        var data = $(this).data();
        appBosch.userData = data;
        var window = $("#wndUser");
        if (!window.data("kendoWindow")) {
            window.removeClass('hidden');
            window.kendoWindow({
                width: 1000,
                autoOpen: false,
                title: data.user,
                actions: [
                    "Close"
                ],
                close: function () {
                    $('#grid').data('kendoGrid').dataSource.read();
                },
                open: function () {
                    var url = [appBosch.urlResumenTeam, appBosch.userData.userId].join('/');
                    $.getJSON(url, {}, initResumen);
                    $('#formUser').trigger("reset");
                    $('#deleteAllCertification').removeAttr('disabled');
                    $('#deleteAllCertification+i.fa').addClass('hidden');
                    this.center();
                }
            });
        }
        else {
            window.data('kendoWindow').title(data.user).open();
        }
    });

    $('#deleteAllCertification').click(function () {
        $(this).attr('disabled', 'disabled');
        $('#deleteAllCertification+i.fa').removeClass('hidden');
        var userId = appBosch.userData.userId;
        var lineId = appBosch.lineId;
        var teamId = appBosch.teamId;
        var parts = [
            appBosch.urlUser,
            lineId,
            teamId,
            userId
        ];
        var url = parts.join('/');
        var params = $('#formUser').serialize();
        $.getJSON(url, params, function (result) {
            if (result === true) {
                $("#wndUser").data('kendoWindow').close();
            }
            else {
                $('#deleteAllCertification').removeAttr('disabled');
                $('#deleteAllCertification+i.fa').addClass('hidden');
                alert('Ocurrio un error al tratar de eliminar las certificaciones');
            }
        });
    });
    /// Fin usuario

    $(document).on('click', '#deleteCertification', function () {
        //$('#deleteCertification').data('kendoButton').enable(false);
        if (confirm('Estas seguro que deseas eliminar esta certificación?') === true) {
            $(this).find('i').removeClass('fa-times').addClass('fa-refresh').addClass('fa-spin');
            var id = $(this).data('id');
            var url = appBosch.urlDestroyCertification + '/' + id;
            $.getJSON(url, {}, function (model) {
                if (model !== false) {
                    $("#wndMH").data('kendoWindow').close();
                }
            });
        }
    });

    $(document).on('click', 'th[data-field="name"][role="columnheader"]', function () {
        appBosch.userData = $(this).data();
        var window = $("#wndUser");
        if (!window.data("kendoWindow")) {
            window.removeClass('hidden');
            window.kendoWindow({
                width: 700,
                height: "380px",
                autoOpen: false,
                title: 'Equipo',
                actions: [
                    "Close"
                ],
                close: function () {
                    $('#grid').data('kendoGrid').dataSource.read();
                },
                open: function () {
                    $('#formUser').trigger("reset");
                    $('#deleteAllCertification').removeAttr('disabled');
                    $('#deleteAllCertification+i.fa').addClass('hidden');
                    this.center();
                }
            });
        }
        else {
            window.data('kendoWindow').title('Equipo').open();
        }
    });

    $(document).on('dblclick', 'td[role="gridcell"] div.certification[data-success!="null"]', function () {
        appBosch.certification = $(this).find('div.icon').data();
        if (appBosch.jsPermissions.crud.read === false) {
            /**
             * Si no tiene permisos de lectura no les permitimos acceder a los 
             * detalles de la certificación.
             */
            return;
        }
        if (appBosch.certification.id === null && appBosch.jsPermissions.crud.create === false) {
            return;
        }
        var iconRefresh = $(this).find('i.fa-refresh');
        var iconLevel = $(this).find('i.level');
        iconRefresh.removeClass('hidden');
        iconLevel.addClass('hidden');
        var partsUrl = [
            appBosch.urlWorkstationConfig,
            appBosch.certification.workstation,
            appBosch.certification.user,
            appBosch.certification.id
        ];
        var url = partsUrl.join('/');
        $.getJSON(url, {}, function (workstationConfigs) {
            iconLevel.removeClass('hidden');
            iconRefresh.addClass('hidden');
            appBosch.certification = workstationConfigs.certification;
            $('div#wndMH>form').html('');
            var code = appBosch.templateTraining(workstationConfigs.certification);
            $('div#wndMH>form').append(code);
            var container = $('div#wndMH div.workstationsConfigs');
            container.html('');
            workstationConfigs.details.forEach(function (wc) {
                var code = appBosch.template(wc);
                container.append(code);
            });
            container.kendoTooltip({
                filter: "label",
                content: kendo.template($("#templateLinks").html()),
                position: "top"
            });
            $("#wndMH input.users").kendoDropDownList({
                dataTextField: "text",
                dataValueField: "value",
                dataSource: appBosch.users
            });
            $("#wndMH input.workstations").kendoDropDownList({
                dataTextField: "name",
                dataValueField: "id",
                dataSource: appBosch.colDyn
            });
            /// Inicio de la certificación
            var startCertification = new Date();
            if (appBosch.certification.cStart !== null) {
                startCertification = new Date(appBosch.certification.cStart.replace(/-/g, '/'));
            }
            $('#formSaveCertification input.cStart').not('.k-input').kendoDatePicker({
                format: 'd',
//                max: new Date(),
                value: startCertification
//                change: function () {
//                    var start = $('input.cStart').data('kendoDatePicker');
//                    var end = $('input.cEnd').data('kendoDatePicker');
//                    var life = $('input.cLife').data('kendoDatePicker');
//                    var endDate = new Date();
//                    endDate.setDate(start.value().getDate() + parseInt(appBosch.certification.wDays));
//                    end.value(endDate);
//                    end.min(start.value());
//                    var lifeDate = new Date();
//                    lifeDate.setDate(start.value().getDate() + parseInt(appBosch.certification.wLife));
//                    life.value(lifeDate);
//                    life.min(start.value());
//                    $('input.kendoDatePicker').each(function (i, obj) {
//                        var dp = $(obj).data('kendoDatePicker');
//                        var current = dp.value();
//                        var startDate = start.value();
//                        if (current < startDate) {
//                            dp.value(startDate);
//                        }
//                        dp.min(start.value());
//                    });
//
//                }
            });
            /// Fin de la certificación
            var endDate = new Date(startCertification);
            if (appBosch.certification.cEnd === null) {
                endDate.setDate(startCertification.getDate() + parseInt(appBosch.certification.wDays));
            }
            else {
                endDate = new Date(appBosch.certification.cEnd.replace(/-/g, '/'));
            }
            $('#formSaveCertification input.cEnd').kendoDatePicker({
                format: 'd',
                value: endDate
//                min: startCertification,
//                change: function () {
//                    var end = $('input.cEnd').data('kendoDatePicker');
//                    $('input.kendoDatePicker').each(function (i, obj) {
//                        var dp = $(obj).data('kendoDatePicker');
//                        var current = dp.value();
//                        var endDate = end.value();
//                        if (current > endDate) {
//                            dp.value(endDate);
//                        }
//                        dp.max(endDate);
//                    });
//                }
            });
            /// Las partes de la certificación
            $('input.kendoDatePicker').kendoDatePicker({
                format: 'd',
                min: startCertification,
                max: endDate,
                change: function () {
                    var name = this.element[0].attributes['for'].nodeValue;
                    var dp = $('.kendoNumeric[name="' + name + '"]').data('kendoNumericTextBox');
                    if (dp !== null && dp.value() === null) {
                        dp.value(100);
                    }
                }
            });
            //Desactivamos los inputs de fechas para que no se pueda escribir la
            //fecha, ahora solamente se puede seleccionar al dar clic en el calendario
            $('input[data-role="datepicker"]').attr('readonly', 'readonly');
            /// Vida de la certificación
            var lifeDate = new Date(startCertification);
            if (appBosch.certification.cLife === null) {
                lifeDate.setDate(startCertification.getDate() + parseInt(appBosch.certification.wLife));
            }
            else {
                lifeDate = new Date(appBosch.certification.cLife.replace(/-/g, '/'));
            }
            $('input.cLife').not('.k-input').kendoDatePicker({
//                min: startCertification,
                value: lifeDate,
                format: 'd'
//                change: function () {
//                    var name = this.element[0].attributes['for'].nodeValue;
//                    var dp = $('.kendoNumeric[name="' + name + '"]').data('kendoNumericTextBox');
//                    if (dp !== null && dp.value() === null) {
//                        dp.value(100);
//                    }
//                }
            });
            var isC = isCertification();
            var lifeCertification = $('input.cLife').data('kendoDatePicker');
            if (lifeCertification !== null) {
                lifeCertification.enable(isC);
            }
            $('#iconCertificate').addClass('hidden');
            if (isC === true) {
                $('#iconCertificate').removeClass('hidden');
            }
            $("input.kendoNumeric").not('.k-input').kendoNumericTextBox({
                min: 0,
                max: 100,
                format: '0',
                change: function () {
                    var value = parseInt(this.value());
                    var minQualification = parseInt(this.element[0].attributes['data-min-qualification'].nodeValue);

                    if (value < minQualification) {
                        var element = $(this.element).parent().parent().parent();
                        element.find('input').css('color', '#d9534f').css('font-weight', 'bold');
                        element.find('i.fa-check').addClass('hidden');
                        element.find('i.fa-times').removeClass('hidden');
                    }
                    else {
                        var element = $(this.element).parent().parent().parent();
                        element.find('input').css('color', '#4c5356').css('font-weight', 'normal');
                        element.find('i.fa-check').removeClass('hidden');
                        element.find('i.fa-times').addClass('hidden');
                    }
                    var name = this.element[0].attributes['for'].nodeValue;
                    var dp = $('.kendoDatePicker[name="' + name + '"]').data('kendoDatePicker');
                    if (dp !== null && dp.value() === null) {
                        var dt = new Date();
                        dt.setHours(0);
                        dt.setMinutes(0);
                        dt.setSeconds(0);
                        dp.value(dt);
                    }
                    var isC = isCertification();
                    var lifeCertification = $('input.cLife').data('kendoDatePicker');
                    if (lifeCertification !== null) {
                        lifeCertification.enable(isC);
                    }
                    $('#iconCertificate').addClass('hidden');
                    if (isC === true) {
                        $('#iconCertificate').removeClass('hidden');
                    }
                }
            });
            $('#saveCertification').click(function () {
                var form = $('#formSaveCertification');
                var url = form.attr('action');
                var params = form.serialize();
                $.getJSON(url, params, function () {
                    $("#wndMH").data('kendoWindow').close();
                });
            });
            var window = $("#wndMH");
            if (!window.data("kendoWindow")) {
                window.kendoWindow({
                    width: 650,
                    height: "420px",
                    title: 'Certificación',
                    actions: [
                        "Close"
                    ],
                    open: function () {
                        this.center();
                    },
                    close: function () {
                        $('#grid').data('kendoGrid').dataSource.read();
                    }
                });

            }
            window.data("kendoWindow").open();
        });
    });

    dataSource = new kendo.data.DataSource({
        serverPaging: true,
        serverSorting: true,
        pageSize: 50,
        transport: {
            read: {
                url: appBosch.crud.read,
                dataType: "json",
                complete: function (e) {
                    var records = JSON.parse(e.responseText);
                    console.log(records);
                    console.log(appBosch.categories);
                    appBosch.users = [];
                    appBosch.summary = {
                        asoc: records.total,
                        wStations: appBosch.colDyn.length,
                        cE: 0,
                        t: 0
                    };
                    records.data.forEach(function (record) {
                        appBosch.users.push({
                            text: record.un,
                            value: record.ui
                        });
                        appBosch.summary[appBosch.categories[record.l].name] = appBosch.summary[appBosch.categories[record.l].name] ? appBosch.summary[appBosch.categories[record.l].name] + 1 : 1;
                        for (var i = 1; i < appBosch.colDyn.length; i++) {
                            if (record['s' + i]) {
                                appBosch.summary.cE += getSuccess(record['s' + i]);
                                appBosch.summary.t += getTraining(record['s' + i]);
                            }
                        }
                    });
                    console.log(appBosch.summary);
                }
            }
        },
        batch: true,
        schema: {
            total: 'total',
            data: 'data',
            type: 'json',
            model: {
                id: "id",
                fields: appBosch.fields
            }
        }
    });
    appBosch.templateFoto = kendo.template($('#templateFoto').html());
    appBosch.templateLinkNomina = kendo.template($('#templateLinkNomina').html());
    appBosch.templateLinkNombre = kendo.template($('#templateLinkNombre').html());
    var colFijas1 = [
        {
            title: "Foto",
            width: 80,
            locked: false,
            template: appBosch.templateFoto
        },
        {
            field: "unm",
            title: "Nomina",
            locked: false,
            width: 70,
            filterable: {
                cell: {
                    operator: "contains"
                }
            },
            template: appBosch.templateLinkNomina
        },
        {
            field: "un",
            title: "Nombre",
            width: 250,
            locked: false,
            template: appBosch.templateLinkNombre
        },
        //{
        //    field: "t.progress",
        //    title: "Objetivo",
        //    template: appBosch.templateProgress,
        //    //headerTemplate: "<div class='head-obj'>Objetivo<div>",
        //    //template: '<span title="#=target.name#">#= kendo.toString(target.progress, "p0")#</span>',
        //    filterable: false,
        //    width: 80
        //},
        {
            field: "nc",
            title: '# certificaciones',
            hidden: true
        }
    ];
    var colDyn = appBosch.colDyn;
    var columnas = colFijas1.concat(colDyn);
    var heightHeader = $('div#header div.navbar').height();
    var heightFooter = $('footer').height();
    var heightAbHeader = $('#ab-header').height();
    grid = $("#grid").kendoGrid({
        pdf: {
            allPages: true,
            fileName: "Kendo UI Grid Export.pdf"
        },
        excel: {
            fileName: "Kendo UI Grid Export.xlsx",
            filterable: true
        },
        resizable: true,
        columnMenu: true,
        filterable: true,
        selectable: true,
        navigatable: true,
        sortable: true,
        height: $(document).height() - heightHeader - heightFooter - heightAbHeader - 50,
        dataBound: gridDataBound,
        dataSource: dataSource,
        columns: columnas
    }).data('kendoGrid');
    
    $('#exportButton').on('click', exportGrid);

    $('#summaryButton').on('click', showSummary);
});

function gridDataBound() {
//    $('.foot-nomina').parent().attr('colspan', '2');
//    $('.foot-name').parent().remove();
//    var ultimo = $('.k-grid-content tbody tr:last-child').clone();
//    $(ultimo).removeAttr('data-uid');
//    $(ultimo).find('td').html("<div class='cert-pie'></div>\n\
//    <div class='borde-top cad-icon'></div>");
//    ultimo = "<tr class='escondido'>" + $(ultimo).html() + "</tr>";
//    $('.k-grid-content tbody').append(ultimo);
//    $('.k-grid-content tbody').append(ultimo);
//    $('.k-grid-content tbody').append(ultimo);
//    $('.k-grid-content tbody').append(ultimo);
//    var grid = $('#grid').data('kendoGrid');
//    var data = grid.dataSource._data;
//    var nCols = appBosch.colDyn.length;
//    data.forEach(function (user) {
//        var sum = 0;
//        for (i = 1; i < nCols; i++) {
//            if (user['s' + i] === '1'){
//                sum++;
//            }
//        }
//        user['progress'] = sum/10;
//    });
//    debugger;
    appBosch.iRow = 1;
}

function isCertification() {
    var c = $('div.workstationsConfigs div.detail i.fa-check').length;
    var c2 = $('div.workstationsConfigs div.detail i.fa-check:visible').length;
    return c === c2;
}

function x(e) {
    var value = parseInt(e.value());
    var minQualification = parseInt(e.element[0].attributes['min-qualification'].nodeValue);
    if (value < minQualification) {
        var element = $(e.element).parent().parent().parent();
        element.find('input').css('color', '#d9534f').css('font-weight', 'bold');
        element.find('i.fa-check').addClass('hidden');
        element.find('i.fa-times').removeClass('hidden');
    }
    else {
        var element = $(e.element).parent().parent().parent();
        element.find('input').css('color', '#4c5356').css('font-weight', 'normal');
        element.find('i.fa-check').removeClass('hidden');
        element.find('i.fa-times').addClass('hidden');
    }
    var name = this.element[0].attributes['for'].nodeValue;
    var dp = $('.kendoDatePicker[name="' + name + '"]').data('kendoDatePicker');
    if (dp !== null && dp.value() === null) {
        var dt = new Date();
        dt.setHours(0);
        dt.setMinutes(0);
        dt.setSeconds(0);
        dp.value(dt);
    }
    var isC = isCertification();
    var lifeCertification = $('input.cLife').data('kendoDatePicker');
    lifeCertification.enable(isC);
    $('#iconCertificate').addClass('hidden');
    if (isC === true) {
        $('#iconCertificate').removeClass('hidden');
    }
}

function initResumen(data) {
    var templateLevels = kendo.template($('#templateLevels').html());
    var codeLevels = templateLevels(data['level']);
    var testId = data['level']['next']['t.id'];
    $('#wndUser div.levels').html(codeLevels);
    $('#dateAttempt').kendoDatePicker({format: 'dd MMMM yyyy', value: new Date()});
    $('button.attempt').click(function () {
        var qualification = parseInt($('#qualificationAttempt').val());
        if (isNaN(qualification) === false) {
            $('button.attempt').attr('disabled', 'disabled');
            $('button.attempt i.fa-refresh').removeClass('hidden');
            $.getJSON(appBosch.urlAddEvaluation, {
                u: appBosch.userData.userId,
                t: testId,
                q: qualification,
                l: appBosch.lineId,
                tt: appBosch.teamId
            }, function (result) {
                if (result !== false) {
                    initResumen(result);
                }
            });
        }
    });
    $('#wndUser div.levels input[type="number"]').kendoNumericTextBox({
        min: 0,
        max: 100,
        format: '0'
    });
    var table = $('#tableResumen tbody');
    var template = kendo.template($('#rowTemplateLinks').html());
    table.html('');
    data['resumen'].forEach(function (record) {
        var code = template(record);
        table.append(code);
    });
    var urlFormatOk = appBosch.urlThemeOK + '/{0}/{1}/{2}';
    var urlFormatNok = appBosch.urlThemeNOK + '/{0}/{1}/{2}';
    table.kendoTooltip({
        filter: ".ok",
        width: 300,
        minHeight: 150, content: {
            url: "../content/web/tooltip/ajax/ajaxContent1.html"
        },
        requestStart: function (e) {
            var userId = e.target.data("userId");
            var lineId = e.target.data("lineId");
            var type = e.target.data("wcName");
            e.options.url = kendo.format(urlFormatOk, userId, lineId, type);
        }
    });
    table.kendoTooltip({
        filter: ".nok",
        width: 300,
        minHeight: 150, content: {
            url: "../content/web/tooltip/ajax/ajaxContent1.html"
        },
        requestStart: function (e) {
            var userId = e.target.data("userId");
            var lineId = e.target.data("lineId");
            var type = e.target.data("wcName");
            e.options.url = kendo.format(urlFormatNok, userId, lineId, type);
        }
    });
}

function survey() {
    var url = [appBosch.urlSurvey, userId].join('/');
    if (!window.data("kendoWindow")) {
        window.kendoWindow({
            width: "600px",
            title: title,
            content: url,
            actions: [
                "Close"
            ],
            open: function () {
                this.center();
            }
        });
    }
    else {
        window.data("kendoWindow").refresh(url).title(title).open();
    }
}

function getIcon(key) {
    return appBosch.categories[key].icon;
}

function getColor(key) {
    return appBosch.categories[key].colour;
}

function getTraining(value) {
    return value & 1;
}

function getSuccess(value) {
    return value >> 1;
}

var pS = 14;
var cS = 10;

function exportGrid() {
    //var cols = grid.columns.length - 3;
    //var pages = Math.ceil(dataSource.total() / pS);
    //var colsMer = Math.ceil(cols/cS);
    //
    //$("#imageable").addClass('png-exporting');
    //
    //loopRows(1, pages, 0, colsMer, cols);
    //
    //grid.setDataSource(dataSource);
    //$("#imageable").removeClass('png-exporting');

    //var header = $('div.k-grid-header table thead');
    //var thead = $('<thead role="rowgroup">');
    //thead.html(header);
    //$('div.k-grid-content table').prepend(thead);


    var gridElement = $('#grid');
    //printableContent = '',
    //win = window.open('', '', 'width=800, height=500'),
    //doc = win.document.open();

    //var htmlStart =
    //    '<!DOCTYPE html>' +
    //    '<html>' +
    //    '<head>' +
    //    '<meta charset="utf-8" />' +
    //    '<title>EntrenaTe</title>' +
    //
    //    '<link rel="stylesheet" type="text/css" href="/css/vendors/bootstrap/min.css?1" />' +
    //    '<link rel="stylesheet" type="text/css" href="/css/vendors/font-awesome/min.css?1" />' +
    //    '<link rel="stylesheet" type="text/css" href="/css/base.css?1" />' +
    //    '<link rel="stylesheet" type="text/css" href="/css/vendors/pictonic/css/pictonic.css?1" />' +
    //    '<link rel="stylesheet" type="text/css" href="/css/controllers/Abilities/admin.css?4" />' +
    //    '<link rel="stylesheet" type="text/css" href="/css/vendors/kendo/kendo.common.min.css" />' +
    //    '<link rel="stylesheet" type="text/css" href="/css/vendors/kendo/kendo.fiori.min.css" />' +
    //
    //
    //    '<style>' +
    //    'html { font: 11pt sans-serif; }' +
    //    '.k-grid { border-top-width: 0; }' +
    //    '.k-grid, .k-grid-content { height: auto !important; }' +
    //    '.k-grid-content { overflow: visible !important; }' +
    //    'div.k-grid table { table-layout: auto; width: 100% !important; }' +
    //    '.k-grid .k-grid-header th { border-top: 1px solid; }' +
    //    '.k-grid-toolbar, .k-grid-pager > .k-link { display: none; }' +
    //    '</style>' +
    //    '</head>' +
    //    '<body>';
    //
    //var htmlEnd =
    //    '</body>' +
    //    '</html>';

    var gridHeader = gridElement.children('.k-grid-header');
    if (gridHeader[0]) {
        var thead = gridHeader.find('thead').clone().addClass('k-grid-header')
            .clone()
            .children('.k-grid-header').remove()
            .end()
            .children('.k-grid-content')
            .find('table')
            .first()
            .children('tbody').before(thead)
            .end()
            .end()
            .end()
            .end()[0].outerHTML;
    } else {
        //printableContent = gridElement.clone()[0].outerHTML;
    }
    //console.log(printableContent);
    //doc.write(htmlStart + printableContent + htmlEnd);
    //doc.close();
    window.print();
}

function loopRows(page, pages, col, colsMer, cols) {
    if(page <= pages) {
        var dt = new kendo.data.DataSource({
            data: dataSource.data(),
            page: page,
            pageSize: pS
        });
        grid.setDataSource(dt);
        loopColumns(page, col, colsMer, cols);
        loopRows(page+1, pages, col, colsMer, cols);
    }
}

function loopColumns(page, col, colsMer, cols) {
    if( col < colsMer) {
        for(k = 0; k < cols; k++) {
            if(k >= col*cS && k < col*cS+cS) {
                grid.showColumn(k+3);
            } else {
                grid.hideColumn(k+3);
            }
        }
        kendo.drawing.drawDOM($("#imageable"))
            .then(function(group) {
                return kendo.drawing.exportImage(group);
            })
            .done(function(data) {
                kendo.saveAs({
                    dataURI: data,
                    fileName: "MH-" + page + "-" + col + ".png",
                    proxyURL: "http://demos.telerik.com/kendo-ui/service/export"
                });
                loopColumns(page, col+1, colsMer, cols);
            });
    }
}


function showSummary() {
    var wndSummary = $('<div></div>');
    var tSummary = kendo.template($('#templateSummary').html());
    wndSummary.append(tSummary(appBosch));
    wndSummary.kendoWindow({
        title: 'Resumen',
        actions: [
            "Close"
        ],
        deactivate: function () {
            this.destroy();
        }
    }).data('kendoWindow').open().center();
}